package com.laowang.project.system.controller;

import java.util.List;

import com.laowang.project.system.domain.MyCyhAuthority;
import com.laowang.project.system.service.MyCyhAuthorityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.laowang.framework.aspectj.lang.annotation.Log;
import com.laowang.framework.aspectj.lang.enums.BusinessType;

import org.springframework.web.bind.annotation.*;
import com.laowang.project.system.domain.MyCyhVipAuthority;
import com.laowang.project.system.service.MyCyhVipAuthorityService;
import com.laowang.framework.web.controller.BaseController;
import com.laowang.framework.web.domain.AjaxResult;
import com.laowang.common.utils.poi.ExcelUtil;
import com.laowang.framework.web.page.TableDataInfo;

/**
 * 会员权益Controller
 *
 * @author laowang
 * @date 2023-06-01
 */
@Api(tags = "会员权益接口")
@RestController
@RequestMapping("/vipAuthority")
public class MyCyhVipAuthorityController extends BaseController {
    @Autowired
    private MyCyhVipAuthorityService myCyhVipAuthorityService;

    @Autowired
    private MyCyhAuthorityService myCyhAuthorityService;

    /**
     * 查询会员权益列表
     */
    @ApiOperation(value = "查询会员权益列表",notes = "")
    //@PreAuthorize("@ss.hasPermi('my:vipAuthority:list')")
    @GetMapping("/list")
    public TableDataInfo list(MyCyhVipAuthority myCyhVipAuthority) {
        startPage();
        List<MyCyhVipAuthority> list = myCyhVipAuthorityService.selectMyCyhVipAuthorityList(myCyhVipAuthority);
        List<MyCyhAuthority> myCyhAuthorities = myCyhAuthorityService.selectMyCyhAuthorityList(null);
        for (MyCyhVipAuthority cyhVipAuthority : list) {
            for (MyCyhAuthority myCyhAuthority : myCyhAuthorities) {
                if (cyhVipAuthority.getAuthorityId().equals(myCyhAuthority.getId())){
                    cyhVipAuthority.setDesc(myCyhAuthority.getIntro());
                }
            }
        }
        return getDataTable(list);
    }

    /**
     * 导出会员权益列表
     */
    @ApiOperation(value = "导出会员权益列表",notes = "")
    @PreAuthorize("@ss.hasPermi('my:vipAuthority:export')")
    @GetMapping("/export")
    public AjaxResult export(MyCyhVipAuthority myCyhVipAuthority) {
        List<MyCyhVipAuthority> list = myCyhVipAuthorityService.selectMyCyhVipAuthorityList(myCyhVipAuthority);
        ExcelUtil<MyCyhVipAuthority> util = new ExcelUtil<MyCyhVipAuthority>(MyCyhVipAuthority.class);
        return util.exportExcel(list, "authority");
    }

    /**
     * 获取会员权益详细信息
     */
    @ApiOperation(value = "获取会员权益详细信息",notes = "")
    @PreAuthorize("@ss.hasPermi('my:vipAuthority:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        MyCyhVipAuthority myCyhVipAuthority = myCyhVipAuthorityService.selectMyCyhVipAuthorityById(id);
        List<MyCyhAuthority> myCyhAuthorities = myCyhAuthorityService.selectMyCyhAuthorityList(null);

        for (MyCyhAuthority myCyhAuthority : myCyhAuthorities) {
            if (myCyhVipAuthority.getAuthorityId().equals(myCyhAuthority.getId())){
                myCyhVipAuthority.setDesc(myCyhAuthority.getIntro());
            }
        }

        return AjaxResult.success(myCyhVipAuthority);
    }

    /**
     * 新增会员权益
     */
    @ApiOperation(value = "新增会员权益",notes = "")
    @PreAuthorize("@ss.hasPermi('my:vipAuthority:add')")
    @PostMapping
    public AjaxResult add(@RequestBody MyCyhVipAuthority myCyhVipAuthority) {
        return toAjax(myCyhVipAuthorityService.insertMyCyhVipAuthority(myCyhVipAuthority));
    }

    /**
     * 修改会员权益
     */
    @ApiOperation(value = "修改会员权益",notes = "")
    @PreAuthorize("@ss.hasPermi('my:vipAuthority:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody MyCyhVipAuthority myCyhVipAuthority) {
        return toAjax(myCyhVipAuthorityService.updateMyCyhVipAuthority(myCyhVipAuthority));
    }

    /**
     * 删除会员权益
     */
    @ApiOperation(value = "删除会员权益",notes = "")
    @PreAuthorize("@ss.hasPermi('my:vipAuthority:remove')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(myCyhVipAuthorityService.deleteMyCyhVipAuthorityByIds(ids));
    }
}
